package kr.saeildamil.androidstudy_second.fragment;

import kr.saeildamil.androidstudy_second.R;
import kr.saeildamil.androidstudy_second.fragment.DialogFragmentTest.NameGenderFragment;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class DialogStyleTheme extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch20_dialogstyletheme);
	}
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.ch20_dialogstyletheme_btn1:
			showDialog(DialogFragment.STYLE_NORMAL,0);
			break;
		case R.id.ch20_dialogstyletheme_btn2:
			showDialog(DialogFragment.STYLE_NO_TITLE,0);
			break;
		case R.id.ch20_dialogstyletheme_btn3:
			showDialog(DialogFragment.STYLE_NO_FRAME,0);
			break;
		case R.id.ch20_dialogstyletheme_btn4:
			showDialog(DialogFragment.STYLE_NO_INPUT,0);
			break;
		case R.id.ch20_dialogstyletheme_btn5:
			showDialog(DialogFragment.STYLE_NORMAL,android.R.style.Theme_Holo);
			break;
		case R.id.ch20_dialogstyletheme_btn6:
			showDialog(DialogFragment.STYLE_NORMAL,android.R.style.Theme_Holo_Light_Dialog);
			break;
		case R.id.ch20_dialogstyletheme_btn7:
			showDialog(DialogFragment.STYLE_NORMAL,android.R.style.Theme_Holo_Light);
			break;
		case R.id.ch20_dialogstyletheme_btn8:
			showDialog(DialogFragment.STYLE_NORMAL,android.R.style.Theme_Holo_Light_Panel);
			break;
		
		}
	}
	void showDialog(int style, int theme){
		FragmentManager fm = getFragmentManager();
		FragmentTransaction tr = fm.beginTransaction();
		Fragment prev = fm.findFragmentByTag("dialog");
		if(prev != null){
			tr.remove(prev);
		}
		tr.addToBackStack(null);
		NameGenderFragment1 newFragment = new NameGenderFragment1().newInstance(style, theme);
		newFragment.show(tr,"dialog");
	}
	public static class NameGenderFragment1 extends DialogFragment{
		static NameGenderFragment1 newInstance(int style, int theme){
			
			NameGenderFragment1 df = new NameGenderFragment1();
			
			Bundle args = new Bundle();
			args.putInt("style", style);
			args.putInt("theme", theme);
			df.setArguments(args);
			
			return df;
			
		}
		
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			
			int style = getArguments().getInt("style");
			int theme = getArguments().getInt("theme");
			
			setStyle(style, theme);
		}
		
		public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			View root = inflater.inflate(R.layout.ch20_namegenderfragment, container, false);
			return root;
		}
		
	}
}
